/**
 * Class CheckRadio Input Module.
 * A kind of checkbox but using 2 radio buttons
 * 
 * Thus, value is a boolean
 * 
 * @author Jean-Luc Scheefer
 */
InputCheckRadioModule.inherits(InputModule);
function InputCheckRadioModule(params) {
	params = Util.getObject(params);
	this.parentConstructor(InputModule, params);
	
	this.setLabelTrue(params.labelTrue);
	this.setLabelFalse(params.labelFalse);
}

InputCheckRadioModule.prototype.DEFAULT_VALUE = true;

/**
 * Fills the given jQuery element
 */
InputCheckRadioModule.prototype.fillJQ = function(jQ) {
	var label = $('<label></label>').append(this.label);
	
	var radios = $('<div class="input ' + this.widthClass + '"></div>');
	var radioTrue = $('<div style="float:left;"></input>');
	var radioFalse = $('<div style="float:right;"></input>');
	radioTrue.append($('<input type="radio"' + (this.value ? ' checked' : '') + (this.readonly ? ' disabled="true"' : '') + ' value="true" name="' + this.labelTrue + '" />'));
	radioFalse.append($('<input type="radio"' + (!this.value ? ' checked' : '') + (this.readonly ? ' disabled="true"' : '') + ' value="false" name="' + this.labelFalse + '" />'));
	radioTrue.append(this.labelTrue);
	radioFalse.append(this.labelFalse);
	radios.append(radioTrue).append(radioFalse);
	jQ.append(label);
	jQ.append(radios);
	var that = this;
	jQ.find('input:radio').change(function() {
		var val = Util.checkBoolTrue($(this).val());
		that.setValue($(this).is(':checked') ? val : !val);
		that.modified = true;
		Util.getFunction(that.onChange).call(that, that.value);
	});
	return jQ;
};

/**
 * Sets the value
 * @param value
 */
InputCheckRadioModule.prototype.setValue = function(value) {
	this.value = value;
	if (!Util.checkBool(value)) {
		this.value = this.DEFAULT_VALUE;
	}
	return this;
};


/**
 * Sets the label for true value
 * @param value String
 */
InputCheckRadioModule.prototype.setLabelTrue = function(labelTrue) {
	this.labelTrue = labelTrue;
	if (!Util.checkString(labelTrue)) {
		this.labelTrue = "1";
	}
	return this;
};

/**
 * Sets the label for false value
 * @param value String
 */
InputCheckRadioModule.prototype.setLabelFalse = function(labelFalse) {
	this.labelFalse = labelFalse;
	if (!Util.checkString(labelFalse)) {
		this.labelFalse = "0";
	}
	return this;
};
